package com.study.utils;

public class TransactionUtil {
    private ConnectionUtil connectionUtil;

    public void setConnectionUtil(ConnectionUtil connectionUtil) {
        this.connectionUtil = connectionUtil;
    }

    public void beginTransaction() {
        try {
connectionUtil.getLocalThreadConnection().setAutoCommit(false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void commitTransaction() {
        try {
            connectionUtil.getLocalThreadConnection().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void rollbackTransaction() {
        try {
            connectionUtil.getLocalThreadConnection().rollback();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void releaseTransaction() {
        try {
            connectionUtil.getLocalThreadConnection().close();
            connectionUtil.removeLocalThreadConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
